<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

	
		<meta name="robots" content="INDEX,FOLLOW" />

   <script language="javascript" type="text/javascript" src="http://st.f2.vnecdn.net/j/v9/jquery-1.7.1.min.js"></script>
<script>
    var base_url            = '/';
  var jq = jQuery.noConflict();
function checkContent() {
    var sCheck = "";

if (jq('#full_name').length > 0) {
       sCheck= replaceTag(trim(jq('#full_name').val()));

        jq('#full_name').val(sCheck);
        if (trimAll(sCheck) == '') {
           alert('Bạn chưa nhập họ tên.');
           jq('#full_name').focus();
            return false;
        }
        else if (sCheck.length > 100) {
            alert('Họ tên không quá 100 ký tự.');
            jq('#full_name').focus();
            return false;
        }
    }

   




var strpost = 'full_name=' + jq('#full_name').val();
    strpost += '&linkvideo=' + jq('#linkvideo').val();


jq.ajax({
            type: "POST",
            cache: false,
            url: base_url+ "backend/them-du-an",
            data: strpost,
            timeout: 600000,
            error: function(xhr, ajaxOptions, thrownError) {
                alert("có lỗi xảy ra");
            },
            success: function(data) {
            alert(strpost);
            }
        });


}

function checkupdate()
{


var strpost = 'full_name=' + jq('#txtname').val();
    strpost += '&linkvideo=' + jq('#txtlinkvideo').val();
    strpost += '&id=' + jq('#idproject').val();


jq.ajax({
            type: "POST",
            cache: false,
            url: base_url+ "backend/create/updateproject",
            data: strpost,
            timeout: 600000,
            error: function(xhr, ajaxOptions, thrownError) {
                alert("có lỗi xảy ra");
            },
            success: function(data) {
                if(data=="done")
                {
                    alert("cập nhập thành công");        
                }
            }
        });



}

function changeProject(){
    eventsid = jq('#cboCode').val();
    jq.ajax({
        url:  base_url+ "backend/create/getprojectbyid/?id="+eventsid
    }).done(function(html) {
        
        var obj = jQuery.parseJSON(html);
      
     
        jq('#txtname').val(obj.name_project);
        jq('#txtlinkvideo').val(obj.video_project);
        jq('#idproject').val(obj.id);
        //location.reload();
    });
}

function checkEmail(txt) {
    txt = trim(txt).toLowerCase();
    var patt = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,6}$/;
    return (txt.match(patt) != null);
}
function trim(iStr) {
    if (iStr.length > 0) {
        while (iStr.charCodeAt(0) <= 32)
            iStr = iStr.substr(1);
        while (iStr.charCodeAt(iStr.length - 1) <= 32)
            iStr = iStr.substr(0, iStr.length - 1);
    }
    return iStr;
}

function trimAll(iStr) {
    if (iStr.length > 0) {
        while (iStr.charCodeAt(0) <= 32)
            iStr = iStr.substr(1);
        while (iStr.charCodeAt(iStr.length - 1) <= 32)
            iStr = iStr.substr(0, iStr.length - 1);
    }
    return iStr.replace(/ |&nbsp;/gi, '');
}

function replaceTag(txt) {
    txt = txt.replace(/</gi, '');
    txt = txt.replace(/>/gi, '');
    txt = txt.replace(/&/gi, '');
    return txt;
}
</script>




</head>
<body>

<form name="frmAdd" id="frmAdd" method="post" enctype="multipart-formdata">
        <fieldset>
        <legend>Tạo Project</legend>

        <label>Tên dự án</label><input type="text" name="full_name" value="" id="full_name" size="30"><br>
         <label>Link Video</label><input type="text" name="linkvideo" value="" id="linkvideo" size="30"><br>

        <label>&nbsp;</label> <input type="button" name="ok" value="Register" onclick="return checkContent();"><br>

        </fieldset>
    </form>


<form name="frmupdate" id="frmupdate" method="post" enctype="multipart-formdata">
        <fieldset>
        <legend>Update Project</legend>
        <?php //var_dump('<pre>',$data['project']); ?>
        <select name="cboCode" id="cboCode" style="width:280px;height:22px;" onchange="changeProject();">

        <?php
            
            

            foreach ($data['project'] as $subcate)
            {
                ?>
                 <option value="<?php echo($subcate['id'])?>"><?php echo($subcate['name_project'])?></option>
                
                <?php
                //var_dump( $subcate['name_project']);
            }
        ?>   
        </select>

        <label>Tên dự án</label><input type="text" name="txtname" value="" id="txtname" size="30"><br>
        <label>Link Video</label><input type="text" name="txtlinkvideo" value="" id="txtlinkvideo" size="30"><br>
        <input type="hidden" name="idproject" value="" id="idproject" size="30"><br>
        <label>&nbsp;</label> <input type="button" name="ok" value="Register" onclick="return checkupdate();"><br>

        </fieldset>
    </form>


</body>
</html>